package com.teen9g.infoplatformserver.config;

import com.google.common.hash.BloomFilter;
import com.google.common.hash.Funnels;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class BloomFilterConfig {

    @Bean
    public BloomFilter<Integer> userBloomFilter() {
        // 预计插入的元素数量
        int expectedInsertions = 1000;
        // 期望的误判率
        double fpp = 0.01;
        BloomFilter<Integer> bloomFilter = BloomFilter.create(
                Funnels.integerFunnel(),
                expectedInsertions,
                fpp
        );
        // 将 1 - 1000 的有效 id 添加到布隆过滤器中
        for (int i = 1; i <= 1000; i++) {
            bloomFilter.put(i);
        }
        return bloomFilter;
    }

    @Bean
    public BloomFilter<Integer> canteenShopBloomFilter() {
        // 预计插入的元素数量
        int expectedInsertions = 1000;
        // 期望的误判率
        double fpp = 0.01;
        BloomFilter<Integer> bloomFilter = BloomFilter.create(
                Funnels.integerFunnel(),
                expectedInsertions,
                fpp
        );
        // 将 1 - 1000 的有效 id 添加到布隆过滤器中
        for (int i = 1; i <= 1000; i++) {
            bloomFilter.put(i);
        }
        return bloomFilter;
    }
}
